package chaojishuzu;

import java.util.Scanner;
/**
 * 主界面
 */
public class StudentUI {
    Scanner sc = new Scanner(System.in);
    SuperArray superArray = new SuperArray();
    /*private Student [] students = new Student[]{
           new Student("法外狂徒",20,"男"),
           new Student("皮城女警",21,"女"),
           new Student("影流之主",23,"男"),
           new Student("厄运小姐",24,"女"),
           new Student("荒漠屠夫",25,"男")
    };
*/
    public void process() {
        System.out.println("欢迎使用XXX学生管理系统");
        menu();
    }
    /**
     * 登录
     */
   /* public void login(){
        for (int i = 0; i < 3; i++) {
            System.out.println("请输入姓名：");
            String name = sc.next();
            System.out.println("请输入性别：");
            String gender = sc.next();
            System.out.println("请输入年龄：");
            int age = sc.nextInt();
            for (int j = 0; j < students.length; j++) {
                if (students[j].getName().equals(name) && students[j].getGender().equals(gender) && age == students[j].getAge()) {
                    System.out.println("登陆成功");
                    index = j;
                    return;
                }
            }
            System.out.println("登录失败，还剩" + (2 - i) + "次");
            if (i == 2) {
                System.out.println("再见");
                System.exit(0);
            }
        }
    }
   */

    /**
     * 菜单
     */
    public void menu() {
        while (true) {
            System.out.println("请选择服务类型：1-增加，2-删除，3-修改，4-查询,5-退出");
            int input = sc.nextInt();
            if (input == 1) {
                add();
            } else if (input == 2) {
                delete();
            } else if (input == 3) {
                alter();
            } else if (input == 4) {
                search();
            } else if (input == 5) {
                System.out.println("再见");
                System.exit(0);
            }
        }
    }

    /**
     * 增加
     */
    public void add() {
        System.out.println("请输入学生姓名");
        String name = sc.next();
        System.out.println("请输入学生性别");
        String gender = sc.next();
        System.out.println("请输入年龄：");
        int age = sc.nextInt();
       Student student = new Student(name,gender,age);
        superArray.add(student);
        System.out.println("添加成功，请重新选择服务类型");
    }

    /**
     * 删除
     */
    public void delete() {
        System.out.println("请输入学生的名字: ");
        String name = sc.next();
        for (int i = 0; i < superArray.size(); i++) {
            Student student = (Student) superArray.get(i);
            if (student.getName().equals(name)) {
                superArray.remove(i);
                System.out.println("删除成功");
                return;
            }
        }
        System.out.println("找不到该学生");
    }

    /**
     * 修改
     */
    public void alter() {
      System.out.println("请输入原姓名：");
        String name = sc.next();
        for (int i = 0;i < superArray.size();i++){
            Student student = (Student) superArray.get(i);
            if (student.getName().equals(name)){
                System.out.println("请输入新姓名：");
                String newName = sc.next();
                System.out.println("请输入新性别：");
                String newGender = sc.next();
                System.out.println("请输入新年龄：");
                int newAge = sc.nextInt();
                student.setName(newName);
                student.setGender(newGender);
                student.setAge(newAge);
                System.out.println("修改成功");
                return;
            }
        }
         /* System.out.println("请输入原性别：");
        String gender = sc.next();
        System.out.println("请输入年龄：" );
        int age = sc.nextInt();
          if (name.equals(students[index].getName()) && gender.equals(students[index].getGender()) && age == students[index].getAge()) {
            System.out.println("请输入新姓名：");
            String newName = sc.next();
            System.out.println("请输入新性别：");
            String newGender = sc.next();
            System.out.println("请输入新年龄：");
            int newAge = sc.nextInt();
            students[index].setName(newName);
            students[index].setGender(newGender);
            students[index].setAge(newAge);
            System.out.println("修改成功，请重新登陆");
            process();
        } else {
            System.out.println("输入错误，请重新选择服务类型");
        }
    }
        */
    }
        /**
         * 查询
         */
       public void search(){
           System.out.println("请输入学生姓名: ");
           String name = sc.next();
           for (int i = 0; i < superArray.size(); i++) {
               Student student = (Student) superArray.get(i);
               if (student.getName().equals(name)) {
                   System.out.println("姓名: " + student.getName() + " 学生性别: " + student.getGender() + " 学生年龄: " + student.getAge());
                   return;
               }
           }

           System.out.println("找不到该学生");
       }
   }

